package com.example.rabbit.six;

import com.example.rabbit.util.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * @Author ifredomvip@gmail.com
 * @Date 2022/8/8 16:34
 * @Version 1.0.0
 * @Description
 **/
public class EmitLog {
    public static String exchangeNameDirect = "direct-logs";
    public static String routingKey = "routingKey1";
    public static void main(String[] args) throws IOException, TimeoutException {

        Channel channel = RabbitMqUtils.getChannel();
        channel.exchangeDeclare(exchangeNameDirect, BuiltinExchangeType.DIRECT);

        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()) {
            String message = scanner.next();
            channel.basicPublish(exchangeNameDirect, routingKey, null, message.getBytes(StandardCharsets.UTF_8));
        }

    }
}
